package com.wefans.wefansapp.common.tool.utils;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Set;

import android.content.Context;

import com.wefans.wefansapp.common.tool.data.MFDataManager;
import com.wefans.wefansapp.common.tool.data.ResGetCountry;

public class MFCountryCodeUtil {

	public static String[] getValueList(Context context) {
		
		String result[] = null;
		
		ResGetCountry dtCountryInfo = MFDataManager.getInstance(context).getCountryInfo();
		Hashtable<String, String> mapCountry = dtCountryInfo.getData();
		
		result = new String[mapCountry.size()];
		
		Set<String> keys = mapCountry.keySet();
		
		int i = 0;
		
        for(String key: keys){
        	result[i] = mapCountry.get(key);
            i++;
        }
        
        return result;
	}
	
	public static String getCodeByValue(Context context, String strValue) {
		
		String strCountryCode = "";
		
		ResGetCountry dtCountryInfo = MFDataManager.getInstance(context).getCountryInfo();
		Hashtable<String, String> mapCountry = dtCountryInfo.getData();
		
		Set<String> keys = mapCountry.keySet();
		
        for(String key: keys){
        	if (strValue.equals(mapCountry.get(key))) {
        		strCountryCode = key;
        		break;
        	}
        }
        
        return strCountryCode;
	}
	
	public static String getValueByCode(Context context, String strCode) {
		
		String strValue = "";
		
		ResGetCountry dtCountryInfo = MFDataManager.getInstance(context).getCountryInfo();
		Hashtable<String, String> mapCountry = dtCountryInfo.getData();
		
		Set<String> keys = mapCountry.keySet();
		
        for(String key: keys){
        	if (strCode.equals(key)) {
        		strValue = mapCountry.get(key);
        		break;
        	}
        }
        
        return strValue;
	}
	
	public static int getIndexByValue(Context context, String strValue) {
		
		int nIdx = -1;
		
		ResGetCountry dtCountryInfo = MFDataManager.getInstance(context).getCountryInfo();
		Hashtable<String, String> mapCountry = dtCountryInfo.getData();
		
		Set<String> keys = mapCountry.keySet();
		
		int i = 0;
        for(String key: keys){
        	if (strValue.equals(mapCountry.get(key))) {
        		nIdx = i;
        		break;
        	}
        	i++;
        }
        
        return nIdx;
	}
}
